package com.example.ykbboom.universitytransportation.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.ykbboom.universitytransportation.POJO.Distance;
import com.example.ykbboom.universitytransportation.R;
import com.example.ykbboom.universitytransportation.Util.LogUtil;
import com.example.ykbboom.universitytransportation.Util.NetUtil;
import com.example.ykbboom.universitytransportation.Util.SharedPrefUtil;
import com.example.ykbboom.universitytransportation.Util.ToastUtil;
import com.example.ykbboom.universitytransportation.View.DistanceDialog;
import com.example.ykbboom.universitytransportation.View.PickerScrollView;

import java.util.ArrayList;
import java.util.List;

public class SettingActivity extends BaseActivity {

    private Toolbar mToolbar;
    private LinearLayout changeRadiusLayout;
    private LinearLayout becomeTouristLayout;
    private LinearLayout userReportLayout;
    private LinearLayout userPointLayout;
    private Intent intent;
    private TextView pointText;
    private TextView modifyDistanceText;
    private Button logoutBtn;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        initView();
    }

    @Override
    public void initView() {
        mToolbar = (Toolbar) findViewById(R.id.toolbar_setting);
        setSupportActionBar(mToolbar);
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.setHomeButtonEnabled(true); //设置返回键可用
            actionBar.setDisplayHomeAsUpEnabled(true);//显示HomeAsUp按钮
            actionBar.setDisplayShowTitleEnabled(false);//不自动显示标题
        }
        logoutBtn = (Button) findViewById(R.id.logout_btn);
        logoutBtn.setOnClickListener(this);
        changeRadiusLayout = (LinearLayout) findViewById(R.id.change_radius_ll);
        changeRadiusLayout.setOnClickListener(this);
        becomeTouristLayout = (LinearLayout) findViewById(R.id.become_tourist_ll);
        becomeTouristLayout.setOnClickListener(this);
        userReportLayout = (LinearLayout) findViewById(R.id.user_report_ll);
        userReportLayout.setOnClickListener(this);
        pointText = (TextView) findViewById(R.id.user_point_ll_text);
        userPointLayout= (LinearLayout) findViewById(R.id.user_point_ll);
        userPointLayout.setOnClickListener(this);
        modifyDistanceText = (TextView) findViewById(R.id.modify_distance_text);
        modifyDistanceText.setText("当前查询订单距离为 "+SharedPrefUtil.getCheckDistance()+" 米,点击修改");
    }
    @Override
    public void onClick(View view){
        switch (view.getId()){
            case R.id.change_radius_ll:
                final DistanceDialog ad=new DistanceDialog(SettingActivity.this);
                ad.setTitle("标题");
                ad.setPositiveButton("确定", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        ad.dismiss();
                        SharedPrefUtil.saveCheckDistance(SharedPrefUtil.getTempCheckDistance());
                        ToastUtil.showToast(SettingActivity.this,"修改距离为:"+SharedPrefUtil.getCheckDistance()+"米。");
                    }
                });
                ad.setNegativeButton("取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        ad.dismiss();
                    }
                });
                break;
            case R.id.become_tourist_ll:
                SharedPrefUtil.saveDriverState(false);
                SharedPrefUtil.saveDriverLatlong("");
                ToastUtil.showToast(this,"切换身份:游客");
                break;
            case R.id.user_report_ll:
                intent = new Intent(this,UserReportActivity.class);
                startActivity(intent);
                break;
            case R.id.user_point_ll:
                NetUtil.checkUserPoint(SharedPrefUtil.getUserPhone(),pointText);
                break;
            case R.id.logout_btn:
                intent = new Intent("com.example.ykbboom.FORCE_OFFLINE");
                sendBroadcast(intent);
        }
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item){
        if (item.getItemId()==android.R.id.home){
            finish();
        }
        return true;
    }
}
